<?php
namespace Tgp;

use Tgp\Request;

class App extends Container
{
    // 框架版本
    const VERSION = '1.0.1';

    /**
     * 当前应用类库命名空间
     * @var string
     */
    protected $namespace = 'app';

    /**
     * 应用根目录
     * @var string
     */
    protected $rootPath = '';

    /**
     * 框架文件目录
     * @var string
     */
    protected $corePath = '';

    /**
     * 应用目录
     * @var string
     */
    protected $appPath = '';
    
    /**
     * Runtime目录
     * @var string
     */
    protected $runtimePath = '';

    /**
     * 配置后缀
     * @var string
     */
    protected $configExt = '.php';

    // 框架核心架构
    public function __construct(string $rootPath = '')
    {
        $this->corePath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR;
        $this->rootPath    = $rootPath ? rtrim($rootPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : $this->getDefaultRootPath();
        $this->appPath     = $this->rootPath . 'app' . DIRECTORY_SEPARATOR;
        $this->runtimePath = $this->rootPath . 'runtime' . DIRECTORY_SEPARATOR;

        
    }

    /**
     * 是否为调试模式
     * @access public
     * @return bool
     */
    public function isDebug(): bool
    {
        return $this->appDebug;
    }

    /**
     * 开启应用调试模式
     * @access public
     * @param bool $debug 开启应用调试模式
     * @return $this
     */
    public function debug(bool $debug = true)
    {
        $this->appDebug = $debug;
        return $this;
    }
    
    /**
     * 获取应用根目录
     * @access protected
     * @return string
     */
    protected function getDefaultRootPath(): string
    {
        $path = dirname($this->corePath);

        return $path . DIRECTORY_SEPARATOR;
    }
}